<?php
class PostForm {
	
	var $ActionSelect;
	var $RealtyTipeSelect;
	var $SettlementSelect;
	var $CityInput;
	var $StreetInput;
	var $AreaInput;
	var $PriceInput;
	var $Description;
	var $PersonName;
	var $eMail;
	var $ICQ;
	var $Phone;
		
	function PostForm($Data){
		$settings = &getService('GlobalSettings');     

		$link = mysql_connect($settings->get('db_host'), $settings->get('db_username'), $settings->get('db_password'));
		mysql_select_db($settings->get('db_name'), $link) or die(mysql_error());
		
		$query = "select * from actions";
		$res = mysql_query($query) or die(mysql_error());
		$this->ActionSelect = "";
		
		$i = 0;
		while ($row=mysql_fetch_array($res)){
			if(!isset($Data->Action)){
				if($i == 0){
					$this->ActionSelect = $this->ActionSelect . "<input type=\"radio\" name=\"action_type\" value=\"" . $row["a_id"] . "\" checked>" . $row["name"] . "</input><br/>\r\n";
					$i++;
				} else {
					$this->ActionSelect = $this->ActionSelect . "<input type=\"radio\" name=\"action_type\" value=\"" . $row["a_id"] . "\">" . $row["name"] . "</input><br/>\r\n";
					$i++;
				}
			} else {
				if($row["a_id"] == $Data->Action){
					$this->ActionSelect = $this->ActionSelect . "<input type=\"radio\" name=\"action_type\" value=\"" . $row["a_id"] . "\" checked>" . $row["name"] . "</input><br/>\r\n";
				} else {
					$this->ActionSelect = $this->ActionSelect . "<input type=\"radio\" name=\"action_type\" value=\"" . $row["a_id"] . "\">" . $row["name"] . "</input><br/>\r\n";
				}
			}
		}
		
		$query = "select t_id, name, main_cat from types where main_cat > 0 order by t_id";
		$res = mysql_query($query) or die(mysql_error());
		$this->RealtyTipeSelect = "<select name=\"realty_type\">";
		
		$opened = 0;
		while ($row=mysql_fetch_array($res)){
			if($row["main_cat"]==2){
				if($opened==1){
					$this->RealtyTipeSelect = $this->RealtyTipeSelect . "</optgroup>\n<optgroup label=\"" . $row["name"] . "\">\n";
				} else {
					$this->RealtyTipeSelect = $this->RealtyTipeSelect . "<optgroup label=\"" . $row["name"] . "\">\n";
					$opened=1;
				}
			} elseif($row["t_id"] == $Data->RealtyType) {
				$this->RealtyTipeSelect = $this->RealtyTipeSelect . "   <option value=\"" . $row["t_id"] . "\" selected>" . $row["name"] . "</option>\n" ;
			} else {
				$this->RealtyTipeSelect = $this->RealtyTipeSelect . "   <option value=\"" . $row["t_id"] . "\">" . $row["name"] . "</option>\n" ;
			}
		}
		$this->RealtyTipeSelect = $this->RealtyTipeSelect . "</select>";
		
		$query = "select s_id, name from settlements order by s_id";
		$res = mysql_query($query) or die(mysql_error());
		$this->SettlementSelect = "<select name=\"settlement_region\">";
		
		while ($row=mysql_fetch_array($res)){
			if($row["s_id"] == $Data->SettlementRegion){
				$this->SettlementSelect = $this->SettlementSelect . "   <option value=\"" . $row["s_id"] . "\" selected>" . $row["name"] . "</option>\n" ;
			} else {
				$this->SettlementSelect = $this->SettlementSelect . "   <option value=\"" . $row["s_id"] . "\">" . $row["name"] . "</option>\n" ;
			}
		}
		
		$this->SettlementSelect = $this->SettlementSelect . "</select>";
		mysql_close($link);
		
		$this->CityInput = "<input type=\"text\" name=\"city\" value=\"" . $Data->SettlementCity . "\" size=\"32\"/>";
		$this->StreetInput = "<input type=\"text\" name=\"street\" value=\"" . $Data->Street . "\" size=\"32\"/>";
		$this->AreaInput = "<input type=\"text\" name=\"space\" value=\"" . $Data->Area . "\" size=\"5\" maxlength=\"5\"/>";
		$this->PriceInput = "<input type=\"text\" name=\"price\" value=\"" . $Data->Price . "\" size=\"10\" maxlength=\"10\"/>";
		$this->Description = "<textarea name=\"description\" Rows=\"5\" cols=\"30\">" . $Data->Description . "</textarea>";
		$this->PersonName = "<input type=\"text\" name=\"pib\" value=\"" . $Data->PersonName . "\" size=\"40\"/>";
		$this->eMail = "<input type=\"text\" name=\"mail\" value=\"" . $Data->eMail . "\" size=\"40\"/>";
		$this->ICQ = "<input type=\"text\" name=\"icq\" value=\"" . $Data->ICQ . "\" size=\"10\"/>";
		$this->Phone = "<input type=\"text\" name=\"phone\" value=\"" . $Data->Phone . "\" size=\"14\"/>";
	}
}
?>